/**
 * Created by yuming619 on 2016/10/21.
 */
//rem适配手机大小�
new function () {
    var _self = this;
    _self.width = 640;//�
    _self.fontSize = 100;//
    _self.widthProportion = function () {
        var p = (document.body && document.body.clientWidth || document.getElementsByTagName("html")[0].offsetWidth) / _self.width;
        return p > 1 ? 1 : p < 0.5 ? 0.5 : p;
    };
    _self.changePage = function () {
        document.getElementsByTagName("html")[0].setAttribute("style", "font-size:" + _self.widthProportion() * _self.fontSize + "px !important");
    }
    _self.changePage();
    window.addEventListener('resize', function () {
        _self.changePage();
    }, false);
};
//模态框取消按钮函数
function dismiss() {
    $(".contain-no").click(function () {
        $(".contain-item").fadeOut();
        $(".contain-item1").fadeOut();
        $(".contain-item2").fadeOut();
    })
}
//输入框提示不同内容
function input_alert(html, time) {
    if (!time) {
        time = 2000;
    }
    var float_element = $(".c-float-popWrap")
    var hei = $(window).height() / 2
    var top = $(document).scrollTop() + hei - 30;
    float_element.css({"top": top + "px"})
    $(".warnMsg").html(html)
    float_element.show()
    setTimeout(function () {
        float_element.hide()
    }, time);
}
//接口同步服务器断点动画
function toastHtml(html, show) {
    var float_element = $(".c-float-popWrap")
    if (show == true) {
        var hei = $(window).height() / 2
        var top = $(document).scrollTop() + hei - 30;
        float_element.css({"top": top + "px"});
        $(".warnMsg").html(html)
        float_element.show();
    } else {
        float_element.fadeOut();
    }
}
/*按钮倒计时*/
var timer;
var countdown = 60;
function settime() {
    if (countdown == 0) {
        document.getElementById("getcode").removeAttribute("disabled");
        document.getElementById("getcode").innerHTML = "获取验证码";
        $("#getcode").css({"background-color": "#09b101"})
        clearTimeout(timer);
        countdown = 60;
        return;
    }
    document.getElementById("getcode").setAttribute("disabled", true);
    document.getElementById("getcode").innerHTML = "重新发送(" + countdown + ")";
    countdown = countdown - 1;
    $("#getcode").css({"background-color": "#cccccc"})
    timer = setTimeout("settime()", 1000);
}
//校验图片类型
function checkPic(file) {
    var jzxmPic = document.getElementById(file.id);
    if (!file.value.match(/.jpg|.jpeg|.png|.bmp|.gif|.JPG|.JPEG|.PNG|.BMP|.GIF/i)) {
        input_alert("图片格式错误,请重新选择 ", 2000);
        return 1;
    } else {
        return 0;
    }
}
//模态框取消按钮函数
function dismiss() {
    $(".contain-no").click(function () {
        $(".contain-item").fadeOut();
        $(".contain-item1").fadeOut();
        $(".contain-item2").fadeOut();
    })
}
//点击显示隐藏
function click_showadr(a, b, c) {
    if ($(c).val() == 0) {
        $(a).show();
        $(b).show();
        $(c).val(1);
    } else {
        $(a).hide();
        $(b).hide();
        $(c).val(0);
    }
};

//收货地址选择所在区域功能
function  chooseDistrict(Dom,status){
    $("#chooseAddr").find('div').removeClass('active')
    $(Dom).addClass("active");
    var districtChoose = $("#districtChoose").find('.districtChoose');
    switch (status){
        case 1:
            districtChoose.hide();
            districtChoose[0].style.display = 'block';
            break;
        case 2:
            districtChoose.hide();
            districtChoose[1].style.display = 'block';
            break;
        case 3:
            districtChoose.hide();
            districtChoose[2].style.display = 'block';
            break;
        default:
            break;
    }
}
function loadCart(show,loaderid,bac) {
    var loader = document.getElementById(loaderid);
    if(!loader){
        return;
    }
    var hei = $(window).height();
    var offHei = loader.style.top;
    loader.style.display = "flex";
    offHei = offHei.substring(0, offHei.length - 2);
    loader.style.height = (hei - offHei) + "px";
    if (show == true) {
        loader.style.display = "block";
        loader.style.zIndex = 1031;
        var loaderHtml = '';
        var spanLen = 12;
        loaderHtml += '<div class="loader-inner line-spin-fade-loader">'
        for (var i = 0; i < spanLen; i++) {
            loaderHtml += '<span></span>'
        }
        loaderHtml += '</div>'
        loader.innerHTML += loaderHtml;
        var spanDom = loader.getElementsByTagName("span");
        for (var j = 0; j < spanDom.length; j++) {
            var distance = 12;
            var angle = (360 / spanDom.length) * j;
            var _top = distance * Math.sin(2 * Math.PI * (angle / 360));
            var _left = distance * Math.cos(2 * Math.PI * (angle / 360));
            var infiniteTime = 0.08;
            setStyle(spanDom[j], {
                top: _top + "px",
                left: _left + "px",
                WebkitTransform: "rotate(" + angle + "deg)",
                //MsTransform: "rotate("+angle+"deg)",
                transform: "rotate(" + angle + "deg)",
                WebkitAnimation: "line-spin-fade-loader 0.96s "+ infiniteTime*j+"s infinite ease-in-out",
                animation: "line-spin-fade-loader 0.96s " + infiniteTime * j + "s infinite ease-in-out",
                opacity: j * (1 / 18) + 0.3
            })
        }
        function setStyle(d, c) {
            for (name in c) {
                d.style[name] = c[name]
            }
        }
    } else {
        loader.style.zIndex = -1;
        if(bac){
            var bacHtml = document.querySelector(bac).outerHTML;
            loader.innerHTML = bacHtml;
        }else{
            loader.innerHTML = '';
        }
        loader.style.display = "none";
    }
};
